﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace Koopakiller.Numerics.Test
{
    [TestClass]
    public class SystemTest
    {
        [TestMethod, TestCategory("Ext: System")]
        public void To2D1()
        {
            int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
            int[,] b = a.To2D(4);
            Assert.AreEqual(1, b[0, 0]);
            Assert.AreEqual(4, b[3, 0]);
            Assert.AreEqual(13, b[0, 3]);
            Assert.AreEqual(16, b[3, 3]);
            Assert.AreEqual(11, b[2, 2]);
        }
        [TestMethod, TestCategory("Ext: System")]
        public void To2D2()
        {
            int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
            int[,] b = a.To2D(5);
            Assert.AreEqual(1, b[0, 0]);
            Assert.AreEqual(5, b[4, 0]);
            Assert.AreEqual(11, b[0, 2]);
            Assert.AreEqual(15, b[4, 2]);
            Assert.AreEqual(8, b[2, 1]);
        }
        [TestMethod, TestCategory("Ext: System")]
        public void To2D3()
        {
            //? source = null
            int[] a = null;
            try
            {
                a.To2D(5);
                Assert.Fail("No exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(ArgumentNullException), ex.GetType());
            }
        }
        [TestMethod, TestCategory("Ext: System")]
        public void To2D4()
        {
            //? stride < 0
            int[] a = { 1 };
            try
            {
                a.To2D(-5);
                Assert.Fail("No exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType());
            }
        }
        [TestMethod, TestCategory("Ext: System")]
        public void To2D5()
        {
            //? length % stride != 0
            int[] a = { 1, 2, 3 };
            try
            {
                a.To2D(2);
                Assert.Fail("No exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType());
            }
        }
        [TestMethod, TestCategory("Ext: System")]
        public void ToJagged2D1()
        {
            int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
            int[][] b = a.ToJagged2D(4);
            Assert.AreEqual(1, b[0][0]);
            Assert.AreEqual(4, b[3][0]);
            Assert.AreEqual(13, b[0][3]);
            Assert.AreEqual(16, b[3][3]);
            Assert.AreEqual(11, b[2][2]);
        }
        [TestMethod, TestCategory("Ext: System")]
        public void ToJagged2D2()
        {
            int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
            int[][] b = a.ToJagged2D(5);
            Assert.AreEqual(1, b[0][0]);
            Assert.AreEqual(5, b[4][0]);
            Assert.AreEqual(11, b[0][2]);
            Assert.AreEqual(15, b[4][2]);
            Assert.AreEqual(8, b[2][1]);
        }
        [TestMethod, TestCategory("Ext: System")]
        public void ToJagged2D3()
        {
            //? source = null
            int[] a = null;
            try
            {
                a.ToJagged2D(5);
                Assert.Fail("No exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(ArgumentNullException), ex.GetType());
            }
        }
        [TestMethod, TestCategory("Ext: System")]
        public void ToJagged2D4()
        {
            //? stride < 0
            int[] a = { 1 };
            try
            {
                a.ToJagged2D(-5);
                Assert.Fail("No exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType());
            }
        }
        [TestMethod, TestCategory("Ext: System")]
        public void ToJagged2D5()
        {
            //? length % stride != 0
            int[] a = { 1,2,3 };
            try
            {
                a.ToJagged2D(2);
                Assert.Fail("No exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType());
            }
        }
    }
}
